from selenium.webdriver.support.ui import WebDriverWait
import time
class Base:
    # 初始化
    def __init__(self,driver):
        self.driver = driver
    # 打开网址
    def open_url(self,url):
        self.driver.get(url)
    # 显示等待+定位
    def find_element(self,loc):
        try:
            WebDriverWait(self.driver,20,0.5).until(lambda driver: driver.find_element(*loc).is_displayed())
            return self.driver.find_element(*loc)
        except Exception as p:
            # time_loc = time.strftime('%Y%m%d %H%M%S')
            print(p)
    def find_elements(self,loc):
        try:
            for i in self.driver.find_elements(*loc):
                return print(i.text)
        except Exception as p:
            print(p)
    # 输入操作
    def send_keys(self,loc,info):
        send_key = self.find_element(loc)
        if send_key:
            send_key.send_keys(info)
    # 点击
    def click(self,loc):
        click_loc = self.find_element(loc)
        if click_loc:
            click_loc.click()
    # 文本
    def text(self,loc):
        return self.find_element(loc).text
    # 隐式等待
    def implicitly_wait(self, loc):
        self.driver.implicitly_wait(int(loc))
    # 刷新
    def refresh(self):
        self.driver.refresh()







